Today I'm going to introduce scripting and scripts, run code, which are instructions for our game
so we can make our game do cool stuff.
It adds behavior to the game.
I am on my first game right from the last video and I'm just going to add a block, right?
I'll go here, hit the little arrow block, cool beans.
And then this is part I'm going to rename it to my part.
All right, now we can add a script to my part.
Let's go ahead and do that.
Hit this plus sign right here and you'll have a bunch of stuff that you can add to your part.
Let's type in script so that it limits the list and you can see that there's three different types of
scripts local module and regular.
We'll do all three.
Today we're going to look at this one.
This script right here is a server script.
It just says script.
Let's rename that to print it.
Whoops.
I made my capital T and you can name it whatever you want.
Just have it make sense.
All right.
So we're going to get a print statement that's put here by default.
Right.
And print it opened automatically if you panic.
Oh, my gosh.
Where's my game?
Just go back here.
My first game.
And there it is.
There's your block and there's your little house.
All right, let's go back to print it.
What happens if you close it?
Oh, bummer.
Go back over here.
Double click and it's open again.
If we run this game, we're going to get this message.
In between these speech quotes in the output window, you may be asking, What's the output window?
Go to view output.
There it is, output window.
And you can make this text bigger and smaller by holding the control down and scroll in the mouse button.
All right, let's play it.
Let's see our print out.
So when the block is loaded into the game, the script's going to fire.
All that happen really, really fast.
Hello world.
And you can see it's a server script, it's running on the server and this is the script name and the
line number of that printout.
This is all very handy to know when you're doing troubleshooting.
If you have 100 parts each with 1000 lines of code and you need to know where the error is, I'm going
to show you about that too.
Then this is going to be very helpful.
Let's go to print it.
Let's turn our game off and then let's go ahead and change the message in between these speech quotes.
This is called a string, right?
It's a data type.
It's a string of characters in between speech quotes.
Let's change our message to my custom message and add an exclamation mark, because it's exciting.
Now, when we run it, it's going to say my custom message still on line one, still in print it.
That's cool and all.
Let's add something to it.
Let's go ahead and copy this line of code.
You can do control C or right click copy.
And then I'm going to go down two lines of this blank space.
You can have blank spaces in your code.
That's fine.
And then I just did a paste.
All right, let's make this my second custom message.
And we run it.
We're going to get two messages.
Notice that that blank line did not affect the output.
Right?
The interpreter just skips over those lines and reads out what makes sense and blank lines.
It doesn't read, but it does tell you, hey, we're on line three.
That's kind of cool because let's go ahead and induce an error and see what happens.
I'm going to say error, right?
And nothing by it.
We'll do something weird to like that.
Cool.
See that red line?
That red line saying something's not right.
Let's run our code.
Look at that big old scary red print.
That's never a good thing, is it?
It says incomplete statement, expected assignment or a function call.
And it said, print it, line two.
And here it says line two.
Let's look at line two.
There it is.
There's our error.
Look at that.
Line three didn't even print because this is interpreted by the roadblocks interpreter.
It stopped when it hit an error.
That's important to know when you're doing troubleshooting.
If you don't get to a print statement, you know that something happened prior to that print statement.
Let's fix our error.
And then let's run it.
Everything's good again.
Look at that.
No errors.
Cool.
I'm going to show you one more thing with print statements.
We're going to a print and then I am going to chain together a couple of messages.
So I'm going to say first message.
Comma.
Second message, comma.
Third message.
Look at that.
So you can do multiple things in this print statement.
You can print multiple messages in a print statement.
You just have them comma delimited.
There we go.
Cubans did not print out the commas.
Right.
Just the stuff in between the speech quotes.
Cool beans.
Let's say one more thing.
I'm going to show you what a comment is.
Right.
You do these two dashes and then you can make a comment in your code, something like, I'm not going
to use this script.
It's just for
education.
And that way, maybe put this on the top.
Control X for cut.
Somebody is going through your code and they're like, Oh, what's this printed do?
Then they know right away.
So the comment isn't read by the interpreter.
It is only for programmers, or maybe for you a long time from now where you forget and you're like,
What is this for?
So when we run it, nothing's going to happen.
Now you're probably thinking That's cool and all, but what happens if I'm playing my game and we don't
even really know how to play a game?
I haven't showed you how to do that.
Let's go ahead and save this off file.
Published Road.
Now let's go over to our Web browser.
And we'll go to w w w dot roadblocks dot com.
I'm on the home page.
My home page.
You do that home.
If you're not there, go to create.
Now we hit this tab to download Roadblock Studio.
When we hit that start creating.
Now all we can do is go to manage my experiences and experiences a game.
I don't know why they changed it.
And let's see.
Here's my first game.
I saved that off a second time for something else.
Let's go to my first game and then click right here.
Notice it's private only you can play it my first game.
Cool beans.
All right.
Now, if I hit this big green button, it's going to play my game in the player.
But nobody else can come in because it is private.
I'm going to go ahead and pause this because it takes a second or two to open up.
Oh, no, it doesn't.
It's open.
Cool.
There I am.
But where's my print?
How do I get to them?
We can do two ways.
We can go to this chat box and do a slash console.
Boom.
There it is.
We can make this smaller.
Oh, we can move it.
I held the mouse down while I was dragging that little corner.
And then I'm going to click on here, hold the mouse down and pull it over.
Now this is on client and we have a server script.
So let's go to server.
Look at that.
There's our messages right there.
My, my custom message, my second one.
You get the idea.
Cool.
Another easy way.
If you have a keyboard, let's close this that has the function keys on it.
You could hit F nine.
There we go.
We got it again.
That's pretty cool.
Anyway, that's a little introduction, very simple introduction to scripts, specifically the print
statement.
And I will see you in the next video.